<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>11组件使用中的细节点</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="app">
        <div ref="divya" @click="handleDiv">我是div</div>
        <counter ref="one" @change="handleChange"></counter>
        <counter ref="two" @change="handleChange"></counter>
        <!-- 对两个counter求和 -->
        <div>{{total}}</div>
    </div>
    <script>
        Vue.component('counter', {
            template: '<div @click="handleClick">{{number}}</div>',
            data: function () {
                return {
                    number: 0
                }
            },
            methods: {
                handleClick() {
                    this.number++
                    this.$emit('change')
                }
            }
        })
        var vm = new Vue({
            el: '#app',
            data: {
                total: 0
            },
            methods: {
                handleChange() {
                    this.total = this.$refs.one.number + this.$refs.two.number
                },
                handleDiv() {
                    console.log(this.$refs.divya);  //<div>我是div</div>
                }
            }
        })
    </script>
</body>

</html>